using System;
using System.Collections.Generic;
using XenoGears.Assertions;

namespace Jink.Core.Json.Converters.Shapes.Core
{
    public class JsonPbag : IJsonPbag
    {
        private Func<IDictionary<String, Type>> _properties = () => { throw AssertionHelper.Fail(); };
        private Func<String, Object> _item_get = name => { throw AssertionHelper.Fail(); };
        private Action<String, Object> _item_set = (name, value) => { throw AssertionHelper.Fail(); };

        private JsonPbag(){}

        public static JsonPbag ReadOnly(Func<IDictionary<String, Type>> properties, Func<String, Object> itemGet)
        {
            return new JsonPbag{_properties = properties, _item_get = itemGet};
        }

        public static JsonPbag ReadWrite(Func<IDictionary<String, Type>> properties, Func<String, Object> itemGet, Action<String, Object> itemSet)
        {
            return new JsonPbag{_properties = properties, _item_get = itemGet, _item_set = itemSet};
        }

        public IDictionary<String, Type> Properties
        {
            get { return _properties(); }
        }

        public Object this[String name]
        {
            get { return _item_get(name); }
            set { _item_set(name, value); }
        }
    }
}